package com.huizluo.module3.substr;

public class FindSubString {

    private static String find(String s1,String s2){
        String longStr;
        String shortStr;
        if (s1.length() >= s2.length()){
            longStr = s1;
            shortStr = s2;
        }else{
            longStr = s2;
            shortStr = s1;
        }

        for (int i=shortStr.length();i > 0;i--){
             //构造滑动块
             for (int j=0,k = i;k<shortStr.length()+1;j++,k++){
                 String tmp = shortStr.substring(j,k);
                 System.out.println(tmp);
                 if (longStr.contains(tmp)){
                     return tmp;
                 }
             }
        }

        return "";
    }

    public static void main(String[] args) {
        String s1 = "asdfghjka";
        String s2 = "aaasdfg";

        String s3 = FindSubString.find(s1,s2);

        System.out.println("最大相同子串" + "[" + s3 + "]");
    }

}
